<template>
	<view class="page">
		<status-bar :title="title"></status-bar>
		<backTop v-if='toTop'></backTop>
		<view v-if='pageData'>
			<view class="top-box" v-if='pageData.detail'>
				<image :src="$imgUrls(pageData.detail.photo)" mode="widthFix"></image>
				<view class="act-list">
					<view class="flex-box flex-between list-title">
						<view class="people-box flex-box align-center">
							<view class="people flex-box" v-if='pageData.detail.v_headimg'>
								<block v-for="(per,j) in pageData.detail.v_headimg" :key='j'>
									<image :src="$imgUrls(per)" mode="aspectFill"></image>
								</block>
							</view>
							<view class="text-box" v-if='pageData.detail.show_browse'>
								<text>{{ pageData.detail.show_browse }}</text>
								<text>人看过</text>
							</view>
						</view>
						<view class="flex-box align-center more-box flex-center" @click="toUrl('kill_list?act_id='+act_id)" v-if="pageData.group_kill">
							<text>查看更多</text>
							<text class="iconfont icon-xiangyouxiayiye"></text>
						</view>
					</view>
					<template v-if='pageData.group_kill'>
						<view class="act-one flex-box" v-for="(item,index) in pageData.group_kill" :key='index' @click="toUrl('goods_list?act_id='+item.act_id)" v-if='pageData.group_kill.length == 1'>
							<image class="act-img" :src="$imgUrls(item.img)" mode="aspectFill"></image>
							<view class="act-msg flex-between flex-box">
								<view class="flex-box" v-if="item.enable_timer == 1">
									<view class="title">
										<count-down txtColor='#EC3D00' bg='#EC3D00' startTxt='距结束' endTxt='本场' :time="parseInt(item.end_time) - seconds"></count-down>
									</view>
								</view>
								<view class="title titleColor" v-else>活动进行中</view>
								<view class="flex-box flex-between align-center">
									<text class="name lines">{{ item.name }}</text>
									<view class="price">
										<text>￥</text>
										<text>{{ item.price }}</text>
										<text>起</text>
									</view>
								</view>
								<swiper style="height: 32rpx;" :autoplay="true" :interval="3000" :duration="800" vertical="true" circular>
									<swiper-item v-if='item.v_headimg || (item.add_time != 0 && item.add_time)'>
										<view class="ps flex-box align-center">
											<image class="avatar" v-if='item.v_headimg' :src="$imgUrls(item.v_headimg)" mode="aspectFill"></image>
											<view class="info" v-if='item.add_time != 0 && item.add_time'>{{ item.add_time }}分钟前参与</view>
											<view class="info" v-if='(item.add_time == 0 || !item.add_time) && item.v_headimg'>已参与</view>
										</view>
									</swiper-item>
									<swiper-item>
										<view class="flex-box">
											<view class="info">{{ item.show_browse }}人想要抢</view>
										</view>
									</swiper-item>
								</swiper>
							</view>
						</view>
					</template>
					<swiper class='swiper' :duration="666" display-multiple-items="2" next-margin="120rpx" v-if='pageData.group_kill.length > 1'>
						<swiper-item v-for="(item,i) in pageData.group_kill" :key='i' @click="toUrl('goods_list?act_id='+item.act_id)">
							<view class="swiper-item">
								<view class="title">
									<count-down txtColor='#EC3D00' bg='#EC3D00' v-if='parseInt(item.start_time) - seconds < 0' startTxt='距结束' endTxt='本场' :time="parseInt(item.end_time) - seconds"></count-down>
									<count-down txtColor='#EC3D00' bg='#EC3D00' v-else startTxt='下一场开始' endTxt='本场' :time="parseInt(item.start_time) - seconds"></count-down>
								</view>
								<image :src="$imgUrls(item.img)" mode="aspectFill" class="img"></image>
								<view class="name lines">{{ item.name }}</view>
								<view class="price">
									<text>￥</text>
									<text>{{ item.price?item.price:'0.00' }}</text>
									<text>起</text>
								</view>
								
								<swiper style="height: 32rpx;" :autoplay="true" :interval="3000" :duration="800" vertical="true" circular>
									<swiper-item v-if='item.v_headimg || (item.add_time != 0 && item.add_time)'>
										<view class="ps flex-box align-center">
											<image class="avatar" v-if='item.v_headimg' :src="$imgUrls(item.v_headimg)" mode="aspectFill"></image>
											<view class="info" v-if='item.add_time != 0 && item.add_time'>{{ item.add_time }}分钟前参与</view>
											<view class="info" v-if='(item.add_time == 0 || !item.add_time) && item.v_headimg'>已参与</view>
										</view>
									</swiper-item>
									<swiper-item>
										<view class="flex-box flex-center">
											<view class="info">{{ item.show_browse }}人想要抢</view>
										</view>
									</swiper-item>
								</swiper>
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>
			<view class="content">
				<view class="act-title flex-box align-center">
					<text></text>
					<image :src="$imgUrls(pageData.detail.ico)" mode="heightFix"></image>
					<text class="lines">{{ pageData.detail.info }}</text>
				</view>
				<swiper :duration="666" class="times" display-multiple-items="2" v-if='pageData.other' @change="actChange">
					<swiper-item v-for="(item,i) in pageData.other" :key='i' @click="actTab(i,item.act_id)">
						<view class="swiper-item" :class="{active: act_id == item.act_id}">
							<template v-if='item.enable_timer == 0'>
								活动进行中
							</template>
							<template v-else>
								<count-down txtColor='#EC3D00' bg='#EC3D00' v-if='parseInt(item.start_time) - seconds < 0' startTxt='距本场结束' endTxt='本场' :time="parseInt(item.end_time) - seconds"></count-down>
								<count-down txtColor='#EC3D00' bg='#EC3D00' v-else startTxt='下一场开始' endTxt='本场' :time="parseInt(item.start_time) - seconds"></count-down>
							</template>
						</view>
					</swiper-item>
				</swiper>
				<template v-if='pageData.goods_list && pageData.goods_list.length > 0'>
					<view class="flex-box cls-box flex-between" v-if='pageData.goods_list.length > 1'>
						<view class="list flex-box" :class="{show: showMore}">
							<view class="item" :class="{active: currentTab == i}" @click="currentTab=i" v-for="(item,i) in pageData.goods_list" :key='i'>{{ item.classify_name || '其他' }}</view>
						</view>
						<text class="iconfont icon-xiangxia" v-if='pageData.goods_list.length > 4' :class="{rotate: showMore}" @click="showMore = !showMore"></text>
					</view>
					
					<view class="goods-box">
						<view class="list" v-if='pageData.goods_list[currentTab].goods'>
							<view class="item flex-box" v-for="(item,i) in pageData.goods_list[currentTab].goods" :key='i' @click="toGoods(item.goods_id)">
								<image :src="$imgUrls(item.img)" mode="aspectFill" class="goods_img"></image>
								<view class="goods_msg flex">
									<view class="name lines">{{ item.name }}</view>
									<view class="flex-box align-center">
										<view class="saled">
											<view :style="{width: 100 - parseFloat(item.stock_percent)+'%'}"></view>
											<text>{{ 100 - parseFloat(item.stock_percent) }}%</text>
										</view>
										<text class="saled-txt">已抢{{ parseInt(item.original_stock) - parseInt(item.stock) }}{{item.unit?item.unit:'件'}}</text>
									</view>
									<view class="flex-box align-center coupon-box">
										<view class="coupon flex-box align-center">
											<image :src="staticUrl+'/images/jh_up/icon-coupon_.png'"></image>
											<text>{{ item.type == 2 ? '团购价' : '秒杀价' }}</text>
										</view>
										<text class="price">{{ item.price }}</text>
									</view>
									<view class="flex-box flex-between btn-box">
										<text class="lines" v-if='item.price_description'>{{ item.price_description }}</text>
										<view class="flex"></view>
										<view class="btn flex-box align-center flex-center">
											<text>{{ item.price_name?item.price_name:'立即购买' }}</text>
											<text class="iconfont icon-xiangyouxiayiye"></text>
										</view>
									</view>
								</view>
							</view>
						</view>
						<empty type='1' cat='2' v-else pad='20' msg='没有找到活动商品哟 ~'></empty>
					</view>
				</template>
				<empty type='1' cat='2' v-else pad='20' msg='没有找到活动商品哟 ~'></empty>
			</view>
		</view>
		<view class="DiLine" v-if='errMsg'>
			<empty type='1' cat='2' :msg='errMsg'></empty>
		</view>
	</view>
</template>

<script>
	let that,seconds = new Date().getTime()/1000;
	export default {
		data() {
			return {
				title:'',
				errMsg: '',
				act_id: '',
				pageData:'',
				staticUrl: this.staticUrl,
				imgUrl: this.imgUrl,
				currentTab: 0,
				toTop: false,
				seconds: seconds,
				showMore: false,
			};
		},
		onShow() {
			that = this
			that.getPageData()
		},
		onLoad(e) {
			that = this
			if(e.act_id){
				that.act_id = e.act_id;
			}else{
				that.errMsg = '参数获取失败！！！'
			}
		},
		methods:{
			actTab(i,act_id){
				if(that.act_id != act_id){
					that.act_id = act_id
					that.getPageData()
				}
			},
			actChange(e){
				that.act_id = that.pageData.other[e.detail.current].act_id
				that.getPageData()
			},
			getPageData(){
				this.$http.post({
					url: '/singleSaleApi/seckillIndex',
					data: {
						bid: uni.getStorageSync('bid'),
						act_id: that.act_id
					}
				}).then(res => {
					if(res.code == 100 && res.data){
						that.title = res.data.detail.name
						uni.setNavigationBarTitle({
							title: res.data.detail.name
						})
						that.pageData = res.data
					}else{
						that.errMsg = res.msg
					}
				})
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 250) {
				this.toTop = true;
			} else {
				this.toTop = false
			}
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #FFFFFF;
	.top-box{
		// min-height: 624rpx;
		position: relative;
		.act-one{
			margin: 0 20rpx;
			padding: 10rpx;
			background-color: #FFF0DF;
			border-radius: 16rpx;
			margin-top: 24rpx;
			.act-img{
				width: 196rpx;
				height: 196rpx;
				border-radius: 16rpx;
			}
			.act-msg{
				width: calc(100% - 196rpx);
				padding: 10rpx;
				padding-left: 20rpx;
				flex-direction: column;
				.title{
					text-align: center;
					
					// line-height: 44rpx;
					font-size: 26rpx;
					border-radius: 10rpx;
					color: white;
					padding: 6rpx 10rpx;
					border: 1px solid #EC3D00;
					white-space: nowrap;
				}
				.name{
					font-size: 28rpx;
					font-weight: bold;
					margin-top: 10rpx;
				}
				.price{
					text-align: center;
					margin-top: 10rpx;
					margin-bottom: 4rpx;
					text{
						color: #D13703;
						&:nth-child(1),&:nth-child(3){
							
						}
						&:nth-child(2){
							font-size: 48rpx;
							font-weight: bold;
						}
					}
				}
				.avatar{
					width: 36rpx;
					height: 36rpx;
					border-radius: 50%;
					margin-right: 8rpx;
				}
				.info{
					color: #666666;
				}
			}
		}
		
		.act-list{
			position: absolute;
			bottom: 74rpx;
			width: 100%;
			z-index: 1;
			.list-title{
				padding: 0 20rpx;
				.people-box{
					height: 48rpx;
					border-radius: 48rpx;
					padding: 0 20rpx 0 8rpx;
					background-color: rgba(255,255,255,0.7);
					.people{
						padding-left: 8rpx;
						image{
							width: 36rpx;
							height: 36rpx;
							border-radius: 50%;
							margin-left: -8rpx;
						}
					}
					.text-box{
						padding-left: 14rpx;
						text{
							&:nth-child(1){
								color: #EC3D00;
							}
							&:nth-child(2){
								color: #333333;
							}
						}
					}
				}
			}
			.more-box{
				padding:0 8rpx 0 18rpx;
				height: 48rpx;
				border-radius: 48rpx;
				background-color: rgba(255,255,255,0.7);
				text{
					color: #EC3D00;
				}
			}
			.swiper{
				margin-top: 24rpx;
				height: 484rpx;
				swiper-item{
					padding-left: 20rpx;
					box-sizing: border-box;
					.swiper-item{
						background-color: #FFF0DF;
						border-radius: 16rpx;
						padding: 14rpx;
						height: 100%;
						box-sizing: border-box;
						.title{
							text-align: center;
							padding: 4rpx 0;
							font-size: 30rpx;
							border: 1px solid #EC3D00;
							border-radius: 10rpx;
							color: white;
							margin-bottom: 14rpx;
							white-space: nowrap;
						}
						.img{
							width: 100%;
							height: 216rpx;
							border-radius: 16rpx;
						}
						.name{
							font-size: 28rpx;
							font-weight: bold;
							margin-top: 10rpx;
						}
						.price{
							text-align: center;
							margin-top: 10rpx;
							margin-bottom: 4rpx;
							text{
								color: #D13703;
								&:nth-child(1),&:nth-child(3){
									
								}
								&:nth-child(2){
									font-size: 48rpx;
									font-weight: bold;
								}
							}
						}
						.avatar{
							width: 36rpx;
							height: 36rpx;
							border-radius: 50%;
							margin-right: 8rpx;
						}
						.info{
							color: #666666;
						}
						
					}
				}
			}
			
		}
	}
	.content{
		margin-top: -46rpx;
		padding-bottom: 40rpx;
		position: relative;
		z-index: 1;
		.act-title{
			height: 88rpx;
			background-color: #FFFFFF;
			border-radius: 88rpx;
			box-shadow: 0px 0px 8rpx 0px rgba(236, 61, 0, 0.2);
			margin: 0 24rpx 0;
			padding: 0 22rpx;
			position: relative;
			z-index: 2;
			text{
				&:nth-of-type(1){
					background-color: #FF3900;
					height: 30rpx;
					width: 6rpx;
					border-radius: 6rpx;
				}
				&:nth-of-type(2){
					color: #666666;
					font-size: 28rpx;
					margin-left: 20rpx;
				}
			}
			image{
				height: 30rpx;
				margin-left: 12rpx;
			}
		}
		.times{
			height: 104rpx;
			border-bottom: 2rpx solid #F5F5F5;
			swiper-item{
				text-align: center;
				display: flex;
				align-items: center;
				justify-content: center;
				.swiper-item{
					border-radius: 10rpx;
					display: inline-block;
					color: #333333;
					padding: 8rpx;
					white-space: nowrap;
					border: 1px solid #DFDFDF;
					&.active{
						border: 1px solid #EC3D00;
					}
				}
			}
		}
		
		.cls-box{
			.list{
				flex-wrap: wrap;
				height: 62rpx;
				overflow: hidden;
				padding-top: 24rpx;
				&.show{
					height: auto;
				}
				.item{
					padding: 0 0 12rpx 24rpx;
					color: #666666;
					font-size: 26rpx;
					&.active{
						color: #333333;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}
			.icon-xiangxia{
				font-size: 30rpx;
				color: #D8D8D8;
				height: 60rpx;
				padding: 30rpx 30rpx 0 24rpx;
				transition: all 0.2s;
				&.rotate{
					transform: rotate(180deg);
				}
			}
		}
		
		.goods-box{
			.list{
				padding: 30rpx;
				.item{
					margin-bottom: 30rpx;
					.goods_img{
						width: 190rpx;
						height: 190rpx;
						border-radius: 16rpx;
					}
					.goods_msg{
						width: calc(100% - 190rpx);
						padding-left: 20rpx;
						.name{
							font-size: 30rpx;
							color: #333333;
							font-weight: bold;
							margin-bottom: 12rpx;
						}
						.saled{
							width: 204rpx;
							height: 26rpx;
							background-color: #F5F5F5;
							border-radius: 26rpx;
							margin-right: 14rpx;
							position: relative;
							text{
								position: absolute;
								top: 50%;
								left: 50%;
								transform: translate(-50%,-50%);
								color: #FE2C00;
							}
							view{
								height: 100%;
								border-radius: 26rpx;
								background: linear-gradient(225deg, #FF9341 0%, #FE2C00 100%);
							}
						}
						
						.saled-txt{
							color: #666666;
							font-size: 26rpx;
						}
						.coupon-box{
							margin-top: 6rpx;
							.coupon{
								border: 1px dotted #FF9A7D;
								border-radius: 6rpx;
								padding: 0 4rpx;
								height: 34rpx;
								margin-right: 10rpx;
								image{
									height: 26rpx;
									width: 20rpx;
									margin-right: 2rpx;
								}
								text{
									color: #FF6539;
									line-height: 26rpx;
									font-size: 24rpx;
								}
							}
							.price{
								font-size: 38rpx;
								font-weight: bold;
								color: #FF3900;
							}
						}
						.btn-box{
							align-items: flex-end;
							>text{
								color: #999999;
								font-size: 22rpx;
								position: relative;
								padding-left: 14rpx;
								margin-bottom: 6rpx;
								&::before{
									content: '';
									width: 4rpx;
									border-radius: 4rpx;
									height: 18rpx;
									background-color: #FF9240;
									display: inline-block;
									position: absolute;
									left: 0rpx;
									top: 50%;
									transform: translateY(-50%);
								}
							}
							.btn{
								min-width: 156rpx;
								padding: 0 10rpx 0 16rpx;
								height: 52rpx;
								border-radius: 52rpx;
								background: #FF3900 linear-gradient(191deg, #FF9240 0%, rgba(255, 255, 255, 0) 100%);
								box-shadow: 0px 0px 8rpx 0px rgba(255, 57, 0, 0.3);
								border-radius: 28rpx;
								text{
									color: white;
								}
								.iconfont{
									font-size: 24rpx;
									margin-left: 6rpx;
								}
							}
						}
					}
				}
			}
		}
	}
	.titleColor{
		color:#D13703 !important;
	}
}
</style>
